﻿//**************************************************
//Description:  消除元素
//Author:       leubooth
//Date:         2016.11.02
//**************************************************

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;

public class Item : MonoBehaviour
{
    /// <summary>
    /// X下标
    /// </summary>
    public int x;

    /// <summary>
    /// Y下标
    /// </summary>
    public int y;

    /// <summary>
    /// 颜色
    /// </summary>
    public Color color;

    /// <summary>
    /// 元素的移动路径节点
    /// </summary>
    public List<Vector3> path = new List<Vector3>();

    /// <summary>
    /// 元素沿着路径节点移动到目标点
    /// </summary>
    public void MoveToTargetByPath()
    {
        if (path.Count == 0) return;
        Vector3[] vector = new Vector3[path.Count];
        for (int i = 0; i < path.Count; i++)
        {
            vector[i] = new Vector3(path[i].x,path[i].y);
        }
        this.transform.DOPath(vector, 1.0f, PathType.Linear);
        x = (int)path[path.Count - 1].x;
        y = (int)path[path.Count - 1].y;
        path.Clear();
    }

    /// <summary>
    /// 元素移动到某目标点
    /// </summary>
    /// <param name="target"></param>
    public void MoveToTarget(Vector3 target)
    {
        x = (int)target.x;
        y = (int)target.y;
        this.transform.DOMove(target,1.0f);
    }
}